import { api } from "../api"
import { message } from "ant-design-vue";
import type { FetchCompetitonParamsType as FetchCompetitonParams } from "@/types/innovation-project";
export async function fetchAllCompetitionsApi(params: FetchCompetitonParams) {
  try {
    const response = await api.get('/java/ground/innovationPlaza/competition/getAllCompetitions', {
      params,
    });
    if (response) {
      // console.log('competitionData', response);

      const res = { records: response.data.records, pages: response.data.pages, total: response.data.total }
      // console.log('res', res);
      return res
    }

    else { message.error('获取项目资料失败'); }
  }
  catch (error) {
    throw new Error('获取项目资料失败')
  }
}

export async function getAnnouncementOSSApi(competitionId: string) {
  try {
    return api.get('/java/ground/innovationPlaza/competition/getAnnouncementOSS', {
      params: {
        projectId: Number(competitionId),
      },
    });
  }
  catch (error) {
    throw new Error('获取项目资料-基本资料失败')
  }
}

export async function getAnnouncementByIdApi(competitionId: string) {
  try {
    return api.get('/java/ground/innovationPlaza/competition/getAnnouncementById', {
      params: {
        competitionId: Number(competitionId),
      },
    });
  }
  catch (error) {
    throw new Error('获取项目资料-基本资料失败')
  }
}

export async function getAnnouncementLinkApi(projectId: string) {
  try {
    return api.get('/java/ground/innovationPlaza/competition/getAnnouncementLink', {
      params: {
        projectId: Number(projectId),
      },
    });
  }
  catch (error) {
    throw new Error('获取项目链接失败')
  }
}
